package com.yonyou.pmclouds.comprehensiveacceptance.rmiimpl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.basecom.billstatus.BillStatusConst;
import com.yonyou.pmclouds.basecom.consts.BillTypeConst;
import com.yonyou.pmclouds.basecom.entity.PageObject;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.runtime.RuntimeEnvironment;
import com.yonyou.pmclouds.basecom.util.SqlUtil;
import com.yonyou.pmclouds.comprehensiveacceptance.entity.ComprehensiveAcceptanceVO;
import com.yonyou.pmclouds.comprehensiveacceptance.entity.AcceptStandardVOToNCC;
import com.yonyou.pmclouds.comprehensiveacceptance.mapper.ComprehensiveAcceptanceVOMapper;
import com.yonyou.pmclouds.comprehensiveacceptance.rmiitf.ComprehensiveAcceptanceQuery;
import com.yonyou.pmclouds.inspectitem.entity.InspectItemBillStatusConst;
import com.yonyou.pmclouds.inspectitem.entity.InspectItemVO;
import com.yonyou.pmclouds.inspectitem.mapper.InspectItemMapper;
import com.yonyou.pmclouds.inspectitem.rmiitf.InspectItemService;
import com.yonyou.pmclouds.inspectitem.util.InspectItemCheckResultEnum;
import com.yonyou.pmclouds.organization.entity.OrganizationVO;
import com.yonyou.pmclouds.organization.rmiitf.OrganizationQuery;
import com.yonyou.pmclouds.picture.rmiitf.PictureRemoteService;
import com.yonyou.pmclouds.pmpub.entity.QueryListParam;
import com.yonyou.pmclouds.pmpub.rmiitf.IPageQuerySerivce;
import com.yonyou.pmclouds.problemlog.entity.ProblemLogBillStatus;
import com.yonyou.pmclouds.project.entity.ProjectBillVO;
import com.yonyou.pmclouds.project.entity.ProjectRefVO;
import com.yonyou.pmclouds.project.entity.ProjectVO;
import com.yonyou.pmclouds.project.mapper.ProjectBillMapper;
import com.yonyou.pmclouds.project.rmiitf.ProjectSimpleQuery;
import com.yonyou.pmclouds.workquality.entity.WorkqualityDetailVO;
import com.yonyou.pmclouds.workquality.entity.WorkqualityVO;
import com.yonyou.pmclouds.workquality.service.rmiitf.WorkqualityQueryService;
import com.yonyou.pmclouds.workstartreport.rmiitf.WorkStartQuery;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.util.*;

@Service(version = ApplicationConsts.APPLICATION_VERSION, interfaceClass = ComprehensiveAcceptanceQuery.class)
public class ComprehensiveAcceptanceQueryImpl implements ComprehensiveAcceptanceQuery , IPageQuerySerivce<ComprehensiveAcceptanceVO> {

    @Autowired
    private ProjectBillMapper projectBillMapper;
    @Autowired
    private ComprehensiveAcceptanceVOMapper acceptanceVOMapper;
    @Autowired
    private WorkqualityQueryService qualityQuery;
    @Autowired
    private InspectItemService itemService;
    @Autowired
    private ProjectSimpleQuery projectSimpleQuery;

    @Autowired
    private PictureRemoteService picService;
    @Autowired
    private InspectItemMapper inspectItemMapper;
    @Autowired
    private OrganizationQuery organizationQuery;
    @Reference(version = ApplicationConsts.APPLICATION_VERSION)
    private WorkStartQuery workStartQuery;

    public static final String[] INCLUDE_BILL_TYPE = {BillTypeConst.PROBLEMLOG_BILLTYPE, BillTypeConst.SAFETY_RECTIFICATION_BILLTYPE};

    public static final Byte[] INCLUDE_BILL_STATUS = {ProblemLogBillStatus.STATUS_REPAIRING, ProblemLogBillStatus.STATUS_ACCEPTING};

    /**
     * 根据项目判定是否能够新增综合验收单
     *
     * @throws BusinessException
     */
    @Override
    public Map<Boolean, String> allowToAdd(String pkProject) throws BusinessException {
        Map<Boolean, String> result = new HashMap<>();
/*        //判断这个项目的开工报告是否还有未审批的项目
        WorkStartVO[] allBill = workStartQuery.getAllBill(pkProject);
        if (allBill.length>0){
            for (WorkStartVO w:allBill){
                if (!w.getBillstatus().equals(9))
                    result.put(Boolean.FALSE, "该项目还有待审批开工报告单据未解决，不能做综合验收");
                return result;
            }
        }*/
        // 确认是否有未解决的项目问题
        List<ProjectBillVO> projectBillVOS = projectBillMapper.queryByIncludeTypeAndStatus(new String[]{pkProject}, INCLUDE_BILL_TYPE, INCLUDE_BILL_STATUS);
        if (projectBillVOS != null && projectBillVOS.size() > 0) {
            result.put(Boolean.FALSE, "该项目还有问题未关闭，不能做综合验收");
            return result;
        }
        // 确认是否已经存在通过的综合验收单
        ComprehensiveAcceptanceVO[] acceptanceVOs = queryByProject(pkProject);
        for (ComprehensiveAcceptanceVO comprehensiveAcceptanceVO : acceptanceVOs) {
//			if (comprehensiveAcceptanceVO.getAcceptanceStatus() == AcceptancePassStatusEnum.PASS.getCode()) {
//				result.put(Boolean.FALSE, "该项目的综合验收已完成，可以到项目详情中查看详情!");
//				return result;
//			}
            if (comprehensiveAcceptanceVO.getBillstatus() == BillStatusConst.COMMON_APPROVED_STATUS ||
                    comprehensiveAcceptanceVO.getBillstatus() == BillStatusConst.COMMON_APPROVING_STATUS) {
                result.put(Boolean.FALSE, "该项目的综合验收已完成，可以到项目详情中查看详情");
                return result;
            }
        }
        // 满足新增条件
        result.put(Boolean.TRUE, "可以添加!");
        return result;
    }

    @Override
    public Map<String, Map<Boolean, String>> checkMakeBillByProjectIds(List<String> projectIdList) throws BusinessException{
        Map<String, Map<Boolean, String>> checkResultMap = new HashMap<>();

        // 校验是否存在未关闭问题
        List<ProjectBillVO> projectBillVOS = projectBillMapper.queryByIncludeTypeAndStatus(projectIdList.toArray(new String[]{}), INCLUDE_BILL_TYPE, INCLUDE_BILL_STATUS);

        String message = "该项目还有问题未关闭，不能做综合验收";
        if(projectBillVOS != null && projectBillVOS.size() > 0){
            for(ProjectBillVO billVO : projectBillVOS){
                Map<Boolean, String> resultMap = new HashMap<>();
                resultMap.put(Boolean.FALSE, message);
                if(checkResultMap.get(billVO.getPkProject()) == null){
                    checkResultMap.put(billVO.getPkProject(), resultMap);
                }
            }
        }

        // 校验是否存在已经审批通过的验收单
        List<ComprehensiveAcceptanceVO> acceptanceVOS = acceptanceVOMapper.queryByProjectIds(projectIdList);
        if(acceptanceVOS != null && acceptanceVOS.size() > 0){
            for(ComprehensiveAcceptanceVO acceptanceVO : acceptanceVOS){
                if (acceptanceVO.getBillstatus() == BillStatusConst.COMMON_APPROVED_STATUS ||
                        acceptanceVO.getBillstatus() == BillStatusConst.COMMON_APPROVING_STATUS) {
                    if(checkResultMap.get(acceptanceVO.getPkProject()) == null){
                        Map<Boolean, String> resultMap = new HashMap<>();
                        resultMap.put(Boolean.FALSE, "该项目的综合验收已完成，可以到项目详情中查看详情");
                        checkResultMap.put(acceptanceVO.getPkProject(), resultMap);
                    }
                }
            }
        }

        for(String projectId : projectIdList){
            if(checkResultMap.get(projectId) == null){
                Map<Boolean, String> resultMap = new HashMap<>();
                resultMap.put(Boolean.TRUE, "可以添加!");
                checkResultMap.put(projectId, resultMap);
            }
        }

        return checkResultMap;
    }



    /**
     * 根据项目主键，获取项目存在的所有验收单信息
     */
    @Override
    public ComprehensiveAcceptanceVO[] queryByProject(String pkProject) throws BusinessException {
        ComprehensiveAcceptanceVO[] acceptanceVOs = acceptanceVOMapper.selectListByPkProject(pkProject);
        if (acceptanceVOs == null || acceptanceVOs.length == 0) {
            return new ComprehensiveAcceptanceVO[0];
        }
        // 填充需要显示的检查标准名称
        fillInspectstandardName(acceptanceVOs);
        // 填充项目信息
        fillProjectInfo(acceptanceVOs);

        getPictures(acceptanceVOs); //添加照片
        return acceptanceVOs;
    }

    /**
     * 添加不合格的检查项中的照片，最多9张
     */
    private void getPictures(ComprehensiveAcceptanceVO[] vos) throws BusinessException {
        Set<String> pkBills = new HashSet<>();
        for (ComprehensiveAcceptanceVO vo : vos) {
            if (vo != null && vo.getPkComprehensiveAcceptance() != null) pkBills.add(vo.getPkComprehensiveAcceptance());
        }
        if (pkBills.size() == 0) return;

        InspectItemVO[] inspectItemVOS = inspectItemMapper.queryByBillPks(SqlUtil.getSqlIn(pkBills.toArray(new String[0])));
        Map<String, String> recordParent = new HashMap<>();
        if (ArrayUtils.isEmpty(inspectItemVOS)) return;

        pkBills.clear();  //清空集合
        for (InspectItemVO vo : inspectItemVOS) {  //取不合格的检查项
            if (vo != null && vo.getBillstatus() == InspectItemBillStatusConst.BILLSTATUS_NO_PASS && vo.getPk_inspectitem() != null) {
                pkBills.add(vo.getPk_inspectitem());  //存入检查项主键
                recordParent.put(vo.getPk_inspectitem(), vo.getPk_bill());
            }
        }
        if (pkBills.size() == 0) return;

        Map<String, List<String>> picMap = picService.queryPicsByPkEntitys(pkBills.toArray(new String[0]));
        if (picMap == null) return;
        Map<String, List<String>> parentPicMap = new HashMap<>();

        for (String key : picMap.keySet()) {
            String pkParent = recordParent.get(key); //检查项主键对应的单据(施工记录)主键
            if (pkParent != null) {   //key是检查项主键
                if (parentPicMap.get(pkParent) == null) {
                    parentPicMap.put(pkParent, new ArrayList<String>());
                }
                if (parentPicMap.get(pkParent).size() < 9) {  //最多取9张照片
                    int need = 9 - parentPicMap.get(pkParent).size();
                    for (int i = 0; i < Math.min(need, picMap.get(key).size()); i++) {
                        parentPicMap.get(pkParent).add(picMap.get(key).get(i));
                    }
                }
            }
        }
        for (ComprehensiveAcceptanceVO vo : vos) {
            if (vo != null && parentPicMap.get(vo.getPkComprehensiveAcceptance()) != null) {
                vo.setPictures(parentPicMap.get(vo.getPkComprehensiveAcceptance()).toArray(new String[0]));
            }
        }
    }

    /**
     * 根据主键获取综合验收单信息
     */
    @Override
    public ComprehensiveAcceptanceVO queryOneByPk(String pkComprehensiveAcceptance) throws BusinessException {
        ComprehensiveAcceptanceVO acceptanceVO = acceptanceVOMapper.selectByPrimaryKey(pkComprehensiveAcceptance);
        // 填充需要显示的检查标准名称
        fillInspectstandardName(new ComprehensiveAcceptanceVO[]{acceptanceVO});
        // 填充项目信息
        fillProjectInfo(new ComprehensiveAcceptanceVO[]{acceptanceVO});
        // 质量标准名称
        WorkqualityVO workqualityVO = qualityQuery.queryByID(acceptanceVO.getPkInspectstandard());
        acceptanceVO.setInspectstandardName(workqualityVO.getCheckname());
        InspectItemVO[] itemVOs = fillInspectItemInfo(acceptanceVO, workqualityVO);
        acceptanceVO.setInspectitems(itemVOs);
        return acceptanceVO;
    }

    /**
     * 填充项目信息
     *
     * @param acceptanceVOS
     * @return void
     * @author yzx
     * @date 2018/6/12 9:46
     */
    private void fillProjectInfo(ComprehensiveAcceptanceVO[] acceptanceVOS) throws BusinessException {
        if (ArrayUtils.isEmpty(acceptanceVOS)) {
            return;
        }
        Set<String> pkProjectSet = new HashSet<String>();

        for (ComprehensiveAcceptanceVO acceptanceVO : acceptanceVOS) {
            pkProjectSet.add(acceptanceVO.getPkProject());
        }


        Set<String> pkSrcOrgSet = new HashSet<>();
        Map<String, ProjectRefVO> projectRefVOMap = projectSimpleQuery.queryRefs(pkProjectSet.toArray(new String[pkProjectSet.size()]));
        for (ComprehensiveAcceptanceVO acceptanceVO : acceptanceVOS) {
            acceptanceVO.setProjectCode(projectRefVOMap.get(acceptanceVO.getPkProject()).getScode());
            acceptanceVO.setProjectName(projectRefVOMap.get(acceptanceVO.getPkProject()).getSname());
            acceptanceVO.setManager(projectRefVOMap.get(acceptanceVO.getPkProject()).getManager());
            if (StringUtils.isNotEmpty(projectRefVOMap.get(acceptanceVO.getPkProject()).getPkOrg()))
                pkSrcOrgSet.add(projectRefVOMap.get(acceptanceVO.getPkProject()).getPkOrg());
        }

        OrganizationVO[] organizationVOs = organizationQuery.queryByPkSrcs(RuntimeEnvironment.getTenantId(), pkSrcOrgSet.toArray(new String[0]));

        Map<String, OrganizationVO> orgMap = new HashMap<>();

        for (OrganizationVO orgVO : organizationVOs) {
            orgMap.put(orgVO.getPkSrc(), orgVO);
        }
        String pkTemp = "";
        for (ComprehensiveAcceptanceVO acceptanceVO : acceptanceVOS) {
            pkTemp = projectRefVOMap.get(acceptanceVO.getPkProject()).getPkOrg();
            if (orgMap.get(pkTemp) != null) {
                acceptanceVO.setOrgName(orgMap.get(pkTemp).getSname());
            }
        }

    }

    /**
     * 填充检查项显示数据
     *
     * @param acceptanceVO
     * @param workqualityVO
     * @return
     * @throws BusinessException
     */
    private InspectItemVO[] fillInspectItemInfo(ComprehensiveAcceptanceVO acceptanceVO, WorkqualityVO workqualityVO)
            throws BusinessException {
        // 查询检查项
        InspectItemVO[] itemVOs = itemService.queryByPkbill(acceptanceVO.getPkComprehensiveAcceptance());
        // 处理检查项名称及描述
        Map<String, WorkqualityDetailVO> qualityMap = new HashMap<String, WorkqualityDetailVO>();
        for (WorkqualityDetailVO workqualityDetailVO : workqualityVO.getItemtabledata()) {
            qualityMap.put(workqualityDetailVO.getPkWorkqualitydetail(), workqualityDetailVO);
        }
        for (InspectItemVO itemVO : itemVOs) {
            WorkqualityDetailVO detailVO = qualityMap.get(itemVO.getPk_item());
            itemVO.setItem_content(detailVO.getCheckdescription());
            itemVO.setItem_name(detailVO.getCheckitem());
        }
        return itemVOs;
    }

    /**
     * 填充综合验收单信息中的检查标准名称
     *
     * @param acceptanceVOs
     * @throws BusinessException
     */
    private void fillInspectstandardName(ComprehensiveAcceptanceVO[] acceptanceVOs) throws BusinessException {
        Set<String> pkInspectstandardSet = new HashSet<String>();
        for (ComprehensiveAcceptanceVO acceptanceVO : acceptanceVOs) {
            pkInspectstandardSet.add(acceptanceVO.getPkInspectstandard());
        }
        Map<String, WorkqualityVO> workqualityVOMap = qualityQuery
                .queryByIDs(pkInspectstandardSet.toArray(new String[pkInspectstandardSet.size()]));

        for (ComprehensiveAcceptanceVO acceptanceVO : acceptanceVOs) {
            WorkqualityVO workqualityVO = workqualityVOMap.get(acceptanceVO.getPkInspectstandard());
            if (workqualityVO != null) {
                acceptanceVO.setInspectstandardName(workqualityVO.getCheckname());
            }
        }
    }

    @Override
    public boolean queryRefByIds(String code, String[] ids) throws BusinessException {
        boolean flag = false;
        Integer count = acceptanceVOMapper.selectRefByCode(code, ids);
        if (count != null && count > 0) {
            flag = true;
        }
        return flag;
    }

    @Override
    public PageObject<Object> queryByCondition(String[] pkProjects, String[] creators, String startDate, String endDate, int[] billStatus, int start, int size) throws BusinessException {

        int count = acceptanceVOMapper.countByCondition(pkProjects, creators, startDate, endDate, billStatus);

        ComprehensiveAcceptanceVO[] comprehensiveAcceptanceVOs =
                acceptanceVOMapper.queryByCondition(pkProjects, creators, startDate, endDate, billStatus, start, size);
        return new PageObject<Object>(setRefFiledINfo(comprehensiveAcceptanceVOs), count, start);
    }

    /**
     * 处理参照字段，非必输项需校验空
     *
     * @param vos
     * @return
     * @throws BusinessException
     */
    private ComprehensiveAcceptanceVO[] setRefFiledINfo(ComprehensiveAcceptanceVO[] vos) throws BusinessException {
        if (ArrayUtils.isEmpty(vos)) {
            return new ComprehensiveAcceptanceVO[0];
        }

        Set<String> projectSet = new HashSet<String>();
        Set<String> standardSet = new HashSet<String>();
        Set<String> pkSet = new HashSet<String>();

        for (ComprehensiveAcceptanceVO vo :
                vos) {
            projectSet.add(vo.getPkProject());
            standardSet.add(vo.getPkInspectstandard());
            pkSet.add(vo.getPkComprehensiveAcceptance());
        }

        Map<String, ProjectVO> projectVOMap = projectSimpleQuery.queryProjects(projectSet.toArray(new String[0]));

        Map<String, WorkqualityVO> workqualityVOMap = qualityQuery.queryByIDs(standardSet.toArray(new String[0]));

        InspectItemVO[] itemVOs = itemService.queryByPkBillsAndStatus(pkSet.toArray(new String[0]), null);

        Map<String, Integer> itemNumsMap = new HashMap<String, Integer>();
        Map<String, Integer> passNumsMap = new HashMap<String, Integer>();

        String tempPkBill = "";
        for (InspectItemVO itemVO :
                itemVOs) {
            tempPkBill = itemVO.getPk_bill();
            if (itemNumsMap.get(tempPkBill) == null) {
                itemNumsMap.put(tempPkBill, 0);
            }

            if (InspectItemBillStatusConst.BILLSTATUS_NOT_FIT != itemVO.getBillstatus()) {
                int num = itemNumsMap.get(tempPkBill) + 1;
                itemNumsMap.put(tempPkBill, num);

                if (InspectItemBillStatusConst.BILLSTATUS_PASS == itemVO.getBillstatus()) {
                    if (passNumsMap.get(tempPkBill) == null) {
                        passNumsMap.put(tempPkBill, 0);
                    }
                    int passNum = passNumsMap.get(tempPkBill) + 1;
                    passNumsMap.put(tempPkBill, passNum);
                }

            }
        }

        for (ComprehensiveAcceptanceVO vo :
                vos) {
            vo.setProjectName(projectVOMap.get(vo.getPkProject()) == null ? null : projectVOMap.get(vo.getPkProject()).getSname());
            vo.setProjectCode(projectVOMap.get(vo.getPkProject()) == null ? null : projectVOMap.get(vo.getPkProject()).getScode());
            vo.setInspectstandardName(workqualityVOMap.get(vo.getPkInspectstandard()) == null ? null : workqualityVOMap.get(vo.getPkInspectstandard()).getCheckname());
            vo.setTotItemNum(itemNumsMap.get(vo.getPkComprehensiveAcceptance()) == null ? 0 : itemNumsMap.get(vo.getPkComprehensiveAcceptance()));
            vo.setPassNum(passNumsMap.get(vo.getPkComprehensiveAcceptance()) == null ? 0 : passNumsMap.get(vo.getPkComprehensiveAcceptance()));
            vo.setUnPassNum(vo.getTotItemNum() - vo.getPassNum());

            if (vo.getTotItemNum() == 0) {
                vo.setPassRate(BigDecimal.ZERO);
            } else {
                vo.setPassRate(new BigDecimal(((double) vo.getPassNum() / (double) vo.getTotItemNum()) * 100).setScale(2, BigDecimal.ROUND_HALF_UP));
            }
        }

        return vos;
    }

    @Override
    public Object checkToCommit(String pkProject) throws BusinessException {
        // 确认是否已经存在通过的综合验收单
        ComprehensiveAcceptanceVO[] acceptanceVOs = queryByProject(pkProject);
        for (ComprehensiveAcceptanceVO comprehensiveAcceptanceVO : acceptanceVOs) {
            if (comprehensiveAcceptanceVO.getBillstatus() == BillStatusConst.COMMON_APPROVED_STATUS ||
                    comprehensiveAcceptanceVO.getBillstatus() == BillStatusConst.COMMON_APPROVING_STATUS) {
                return true;
            }
        }
        return false;
    }



    @Override
    public int countByProject(QueryListParam param) throws BusinessException{

        int count = acceptanceVOMapper.countByCondition(new String[]{param.getPkProject()}, null, param.getStartDate(), param.getEndDate(), null);

        return count;
    }

    @Override
    public ComprehensiveAcceptanceVO[] queryByProject(QueryListParam param) throws BusinessException {

        ComprehensiveAcceptanceVO[] vos = acceptanceVOMapper.queryByCondition(new String[]{param.getPkProject()}, null, param.getStartDate(), param.getEndDate(), null,param.getPageStart(),param.getPageSize());

        return setRefFiledINfo(vos);
    }

    @Override
    public AcceptStandardVOToNCC getInspectionStandardToNCC(String pkProject) throws BusinessException {
        AcceptStandardVOToNCC standardVOToNCC = new AcceptStandardVOToNCC();
        if(StringUtils.isEmpty(pkProject)){
            standardVOToNCC.setErrorMessage("获取参数值pkProject为空，请检查该参数信息！");
            return standardVOToNCC;
        }

        ProjectVO projectVO = projectSimpleQuery.queryByPkSrc(null, pkProject);
        boolean hasProject = projectVO != null;
        standardVOToNCC.setHasProject(hasProject);
        if(!hasProject){
            return standardVOToNCC;
        }

        List<String> pkProjectList = new ArrayList<>();
        pkProjectList.add(projectVO.getPkProject());
        List<ComprehensiveAcceptanceVO> acceptanceVOS = acceptanceVOMapper.queryByProjectIds(pkProjectList);
        boolean hasAcceptance = acceptanceVOS != null && acceptanceVOS.size() > 0;
        standardVOToNCC.setHasAcceptance(hasAcceptance);
        if(!hasAcceptance){
            return standardVOToNCC;
        }

        ComprehensiveAcceptanceVO acceptanceVO = null;
        for(ComprehensiveAcceptanceVO acceptanceVOTemp : acceptanceVOS){
            if(acceptanceVOTemp.getBillstatus() != BillStatusConst.COMMON_APPROVED_STATUS){
                continue;
            }
            acceptanceVO = acceptanceVOTemp;
        }

        if(acceptanceVO == null){
            standardVOToNCC.setHasAcceptance(false);
            return standardVOToNCC;
        }

        WorkqualityVO workqualityVO = qualityQuery.queryByID(acceptanceVO.getPkInspectstandard());
        if(workqualityVO == null){
            return standardVOToNCC;
        }

        standardVOToNCC.setWorkqualityVO(workqualityVO);

        WorkqualityDetailVO[] detailVOS = workqualityVO.getItemtabledata();
        if(detailVOS == null || detailVOS.length <= 0){
            return standardVOToNCC;
        }

        InspectItemVO[] inspectItemVOS = itemService.queryByPkbill(acceptanceVO.getPkComprehensiveAcceptance());

        List<String> pkInspectItemList = new ArrayList<>();

        for(InspectItemVO inspectItemVO : inspectItemVOS){
            pkInspectItemList.add(inspectItemVO.getPk_inspectitem());
        }

        InspectItemVO[] newInspectItemVOS = itemService.queryInspectItemsInfoByPks(pkInspectItemList.toArray(new String[]{}));

        Map<String, InspectItemVO> inspectItemVOMap = new HashMap<>();
        for(InspectItemVO inspectItemVO : newInspectItemVOS){
            inspectItemVOMap.put(inspectItemVO.getPk_item(), inspectItemVO);
        }

        for(WorkqualityDetailVO detailVO : detailVOS){
            InspectItemVO inspectItemVO = inspectItemVOMap.get(detailVO.getPkWorkqualitydetail());
            if(inspectItemVO == null){
                continue;
            }
            detailVO.setMeasuredData(inspectItemVO.getDatas());
            byte checkFlag = inspectItemVO.getBillstatus();
            detailVO.setCheckResult(InspectItemCheckResultEnum.getName(String.valueOf(checkFlag)));

        }

        return standardVOToNCC;
    }

    @Override
    public String getBillType() {
        return BillTypeConst.COMPREHENSIVE_ACCEPTANCE_BILLTYPE;
    }
}
